import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:school_assistant_m/api/home/home_api.dart';
import 'package:shared_preferences/shared_preferences.dart';

class HomeController extends GetxController {
  //TODO: Implement HomeController
  //加载圈
  bool isLoading = true;
  final HomeApi homeApi = Get.find<HomeApi>();

  // 页面控制器
  late final PageController pageController;
  // 当前底部导航下标
  int currentIndex = 0;

  /// 获取用户信息请求
  Future<void> getUserInfo() async {
    isLoading = true;
    Map<String, dynamic> res = await homeApi.getUserInfo();
    // print('--res---------------------');
    // print(res);
    isLoading = false;
    update();
  }

  // 点击底部导航栏的事件
  handleNavBarTap(int index) {
    currentIndex = index;
    pageController.jumpToPage(index);
    update();
  }

  @override
  void onInit() {
    super.onInit();
    getUserInfo();
    pageController = PageController(initialPage: currentIndex);
  }

  @override
  void onClose() {
    pageController.dispose();
    super.onClose();
  }
}
